#ifndef PLAYERPAGE_H
#define PLAYERPAGE_H

#include <QWidget>
#include <QMouseEvent>
#include "volume.h"
#include "playspeed.h"
#include "./mpv/mpvplayer.h"
#include <QDialog>
#include <QFrame>
#include "bullectscreenitem.h"

namespace Ui {
class PlayerPage;
}

class PlayerPage : public QWidget
{
    Q_OBJECT

public:
    explicit PlayerPage(QWidget *parent = nullptr);
    ~PlayerPage();

    // 鼠标按下
    void mousePressEvent(QMouseEvent* event);

    // 鼠标移动
    void mouseMoveEvent(QMouseEvent* event);

    void startPlaying(const QString& videoPath);
private slots:
    // 音量调节、倍速播放
    void onVolumeBtnClicked();
    void onSpeedBtnClicked();
    void onLikeImageBtnClcked(); // 点赞
    void onPlayBtnClicked();
    void onPlaySpeedChanged(double speed);
    void setVolume(int volume);
    void onPlayPosiionChanged(int64_t playTime);
    void onSetPlayProgress(double playRatio);
    void onBullectScreenBtnClicked(); // 弹幕开关
    // 发送弹幕槽函数
    void onSendBulletScreenBtnClicked(const QString& text);
private:
    // 移动窗口控件
    void moveWindows(const QPoint& point);
    QString secondToTime(int64_t seconds);

    // 布局弹幕主窗口
    void initBarrageArea();

    // 构造弹幕数据
    void buildBullectScreenData();

    // 显示弹幕数据
    void showBullectScreen();
private:
    Ui::PlayerPage *ui;

    QPoint dragPos;

    // 音量调节窗口的指针
    Volume* volume;
    PlaySpeed* playSpeed; // 倍数播放窗口

    // 添加MpvPlayer的对象
    MpvPlayer* mpvPlayer = nullptr;

    bool isPlay = false;
    int64_t playTime = 0;
    QString videoPath;

    // 弹幕相关成员
    QDialog* barrageArea;
    QFrame* top;
    QFrame* middle;
    QFrame* bottom;
    QMap<int64_t, QList<BullectScreenInfo>> bullectScreens;
    bool isStartBs = true; // 默认情况下打开
};

#endif // PLAYERPAGE_H
